<template>
  <el-form :model="form" class="form" label-width="80px" label-position="right">
    <el-form-item label=" 菜单id">
      <el-input v-model="form.menuId" placeholder="请填写 菜单id" />
    </el-form-item>
    <el-form-item label=" 角色id">
      <el-input v-model="form.roleId" placeholder="请填写 角色id" />
    </el-form-item>
    <el-row>
      <el-col :span="6">
        <el-form-item>
          <el-button type="primary" @click="edit">{{ loadingText }}</el-button>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item>
          <el-button type="primary" @click="cancel">取消</el-button>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import sysRoleMenu from '@/api/sysRoleMenu'
export default {
  data() {
    return {
      form: {
        id: ''
      },
      loadingText: '保存'
    }
  },
  created() {
    const id = this.$route.params.id
    if (id) {
      this.form.id = id
      this.loadingText = '编辑'
      this.getDetailById(id)
    } else {
      this.loadingText = '保存'
    }
  },
  methods: {
    getDetailById(id) {
      sysRoleMenu.getById(id).then(res => {
        this.form = res.data
      })
    },
    edit() {
      sysRoleMenu.edit(this.form).then(res => {
        this.$message.success(res.message)
        this.$router.push('/sysRoleMenu/index')
      })
    },
    cancel() {
      this.$parent.closePop()
    }
  }
}
</script>
<style>
.form{
  margin: auto auto;
}
</style>
